home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / FORMRUNS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.3 KB  |  43 lines

  1. /*  formruns.c - form initial runs from input file */
  2. #include   "stdio.h"
  3. #include   "cminor.h"
  4. #include   "merge1.h"
  5.  
  6. extern int (*compfun) () ;    /* address of compare function */
  7.  
  8. FILE *do_open() ;        /* opens file & checks for errors */
  9.  
  10. int  formruns(fromfile,scr,tofile)
  11.   char    fromfile[]   ;        /* input file name */
  12.   char    scr[] ;         /* pointers to lines of text */
  13.   char    tofile[] ;        /* put output here */
  14.   {
  15.      int   irun ,nrec , ret ;
  16.      char  sarea[SSIZE ] ;    /* storage area for text lines */
  17.      char  *p[ MAX_REC ] ;    /* pointers to lines of text */
  18.      FILE  *infile ;        /* input file */
  19.      char  oname[68] ;        /* build scratch file names here */
  20.  
  21.      infile = do_open(fromfile,"r") ;   /* open input file */
  22.  
  23.      initfill(infile) ;     /* initialize for fillarea */
  24.      irun = 0 ;
  25.      do
  26.     {            /* read text file into storage area */
  27.        ret = fillarea(sarea,SSIZE,p,MAX_REC,&nrec,infile) ;
  28.        memsort(p,nrec,compfun) ; /* sort using compare function */
  29.                 /* now write out sorted lines */
  30.        if( (ret != AT_EOF) || (irun > 0) )
  31.           mkname(oname,tofile) ;    /* use scratch    file */
  32.        else strcmp(oname,tofile) ;    /* one run - use output file */
  33.        outfile(p,nrec,oname) ;
  34.        irun = irun + 1 ;
  35.     }  while( ret != AT_EOF ) ;
  36.  
  37.      do_close(infile,fromfile) ;
  38.      return( irun ) ;
  39.   }
  40.  
  41.  
  42.  
  43.